//
//  manageMyResumeCells.swift
//  DingDongZP
//
//  Created by 三秒文化 on 16/4/14.
//  Copyright © 2016年 iyhjiang.com. All rights reserved.
//

import UIKit

class manageMyResumeCells: UITableViewCell {

    var titleLab:UILabel?
    var descLab:UILabel?
    var divideLine:UIImageView?
    var secBtn:UIButton?
    var tapColsure:((cell:manageMyResumeCells)->Void)?
    
    var expectjobid:String?
    
    var selexp_id:String?
    
    var isCurrentExpJob:Bool = false
    
    var model:LDUserInfoExpectedJobModel? {
        
        didSet{
            
            expectjobid = model?.expectjobid
            
            if expectjobid == selexp_id {
                secBtn?.selected = true
                isCurrentExpJob = true
            } else {
                secBtn?.selected = false
                isCurrentExpJob = false
            }
            
            if model?.expectcity_name != nil && model?.expectjobcategory_name != nil{
                
                titleLab?.text = "[\((model?.expectcity_name)! as String)] \((model?.expectjobcategory_name)! as String)"
            }
            
            var jobtagstitle = String()
            for item in model!.industries! {
                
                let str = item["industry_name"] as? String ?? ""
                
                jobtagstitle.appendContentsOf("\(str) ")
                
                debugPrint(str)
            }
            
            if model?.expectsalary_text != nil {
                descLab?.text = "\(model!.expectsalary_text!)  " + jobtagstitle
            }
        }
    }
    
    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        selectionStyle = .None
        setDefaultContent()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

    func setDefaultContent() {
        titleLab = UILabel.setDetailsLab("city-Name", fontSize: 16, titleColor: LDFontColor.DeepGray, Alignment: .Left)
        descLab = UILabel.setDetailsLab("salary-kinds", fontSize: 14, titleColor: LDFontColor.LightGray, Alignment: .Left)

        secBtn = UIButton()
        secBtn?.setImage(UIImage(named: "btn_check_on_disabled_holo_light"), forState: .Normal)
        secBtn?.setImage(UIImage(named: "btn_check_on_holo_dark"), forState: .Selected)
        
//        secBtn?.bk_whenTapped({ [weak self] in
////            self?.secBtn?.selected = !(self?.secBtn?.selected)!
//            guard self?.tapColsure == nil else {
//                self?.tapColsure!(cell: self!)
//                return
//            }
//        })
        secBtn?.addTarget(self, action: #selector(sendColsure), forControlEvents: UIControlEvents.TouchUpInside)
        
        divideLine = UIImageView.setupDivideLine_H(LDFrame.ScreenWidth - LDMargin_H*6)
        
        addSubview(secBtn!)
        addSubview(titleLab!)
        addSubview(descLab!)
        addSubview(divideLine!)
        
        
        titleLab?.snp_makeConstraints(closure: { (make) in
            make.top.equalTo(LDMargin_H*4)
            make.left.equalTo(LDMargin_H*4)
            make.height.equalTo(20)
        })
        
        descLab?.snp_makeConstraints(closure: { (make) in
            make.top.equalTo((titleLab?.snp_bottom)!).offset(LDMargin_V*2)
            make.left.equalTo(titleLab!)
            make.height.equalTo(20)
        })
        
        secBtn?.snp_makeConstraints(closure: { (make) in
            
            make.centerY.equalTo(self)
            make.right.equalTo(-LDMargin_H*3)
            make.width.height.equalTo(35)
        })
        
        divideLine?.snp_makeConstraints(closure: { (make) in
            make.bottom.equalTo(self).offset(-0.5)
            make.left.equalTo(titleLab!)
            make.right.equalTo(-LDMargin_H*5)
            make.height.equalTo(0.5)
        })
    }
    
    func sendColsure () {
        if tapColsure != nil {
            tapColsure!(cell: self)
        }
    }
    
    func tapBtnSelColsure(closure:((selcell:manageMyResumeCells)->Void)?) {

        tapColsure = closure

    }
    
    override func setSelected(selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)
    }
}

